/*
  Name: GPS module RS232 communication library
  Copyright: 
  Author: JackyCA.Liu
  Date: 19/07/11 09:34
  Description: 
*/
#ifndef _RS232_H_
#define _RS232_H_

//Library version 0.0.1
#define GPS_LIB_VERSION_MAJOR 0
#define GPS_LIB_VERSION_MINOR 0
#define GPS_LIB_VERSION_BUILD 1


#include <stdio.h>
#include <Windows.h>
#include <conio.h>
#include <string.h>

#include "rs232_util.h"
#include "checksum.h"
#include "Error_handling.h"

#define true 1
#define false 0

#define BLOCK_SIZE 40

#define INPUT_BUFFER_SIZE 10240
#define OUTPUT_BUFFER_SIZE 10240

HANDLE hComm;
OVERLAPPED osReader = {0};
long EvWait;

HANDLE    hThread;
DWORD    dwThread;

#define COM_PORT_1 "COM1"
#define COM_PORT_2 "COM2"
#define COM_PORT_3 "COM3"
#define COM_PORT_4 "COM4"
#define COM_PORT_5 "COM5"
#define COM_PORT_6 "COM6"
#define COM_PORT_7 "COM7"
#define COM_PORT_8 "COM8"
#define COM_PORT_9 "COM9"
#define COM_PORT_10 "COM10"
#define COM_PORT_11 "COM11"
#define COM_PORT_12 "COM12"
#define COM_PORT_13 "COM13"
#define COM_PORT_14 "COM14"
#define COM_PORT_15 "COM15"
#define COM_PORT_16 "COM16"
#define COM_PORT_17 "COM17"
#define COM_PORT_18 "COM18"
#define COM_PORT_19 "COM19"
#define COM_PORT_20 "COM20"

#define BAUD_RATE_110	CBR_110
#define BAUD_RATE_300	CBR_300
#define BAUD_RATE_600	CBR_600
#define BAUD_RATE_1200	CBR_1200
#define BAUD_RATE_2400	CBR_2400
#define BAUD_RATE_4800	CBR_4800
#define BAUD_RATE_DEFAULT	CBR_9600
#define BAUD_RATE_14400 CBR_14400
#define BAUD_RATE_19200 CBR_19200
#define BAUD_RATE_38400 CBR_38400
#define BAUD_RATE_56000 CBR_56000
#define BAUD_RATE_57600 CBR_57600
#define BAUD_RATE_115200 CBR_115200
#define BAUD_RATE_128000 CBR_128000
#define BAUD_RATE_256000 CBR_256000

#define BYTE_SIZE_DEFAULT	8

#define PARITY_DEFAULT		NOPARITY
#define PARITY_EVENPARITY	EVENPARITY
#define PARITY_MARKPARITY	MARKPARITY
#define PARITY_ODDPARITY	ODDPARITY
#define PARITY_SPACEPARITY	SPACEPARITY

#define STOP_BITS_DEFAULT	ONESTOPBIT

#define READ_INTERVAL_TIMEOUT_DEFAULT MAXDWORD

struct _SerialConfig {
    char portName[6];
    DWORD BaudRate; 
	BYTE  ByteSize;
    BYTE  Parity;
    BYTE  StopBits;
	DWORD ReadIntervalTimeout;
};

void ReadData();
long WriteData(char *str);
long GPSInitialize();
long GPSDeinitialize();
void DefaultConfig(struct _SerialConfig *Serialconfig);

struct _LibVersion {
	int major;
	int minor;
	int build;
};

void GPSGetLibVersion(struct _LibVersion *LibVersion);

#define GPS_NMEA_FILTER_GPBOD	1
#define GPS_NMEA_FILTER_GPBWC	2
#define GPS_NMEA_FILTER_GPGGA	4
#define GPS_NMEA_FILTER_GPGLL	8
#define GPS_NMEA_FILTER_GPGSA	16
#define GPS_NMEA_FILTER_GPGSV	32
#define GPS_NMEA_FILTER_GPHDT	64
#define GPS_NMEA_FILTER_GPR00	128
#define GPS_NMEA_FILTER_GPRMA	256
#define GPS_NMEA_FILTER_GPRMB	512
#define GPS_NMEA_FILTER_GPRMC	1024
#define GPS_NMEA_FILTER_GPRTE	2048
#define GPS_NMEA_FILTER_GPTRF	4096
#define GPS_NMEA_FILTER_GPSTN	8192
#define GPS_NMEA_FILTER_GPVBW	16384
#define GPS_NMEA_FILTER_GPVTG	32768
#define GPS_NMEA_FILTER_GPWPL	65536
#define GPS_NMEA_FILTER_GPXTE	131072
#define GPS_NMEA_FILTER_GPZDA	262144

#endif